# -*- coding: utf-8 -*-
# @Time    : 2021/11/13 20:46
# @Author  : travel2040
# @Email   : travel2040@163.com
# @File    : 文件夹到文件夹.py

import os
def batchGetPictureFiles(picturesDir):


    picturesFiles = []
    # for root, dirs, files in os.walk(picturesDir):
    #     # print(root)  # 当前目录路径
    #     # print(dirs)  # 当前路径下所有子目录
    #     # print(files)  # 当前路径下所有非目录子文件
    #     for file in files:
    #         if file.endswith(".jpg"):
    #             picturesFile = os.path.join(picturesDir,file)
    #             print(picturesFile)
    #             picturesFiles.append(picturesFile)

    for i in range(33):
        file = "atlasMap_{}.jpg".format(i)
        picturesFile = os.path.join(picturesDir,file)
        if os.path.exists(picturesFile):
            # print(picturesFile)
            picturesFiles.append(picturesFile)

    return picturesFiles
def batchSavePicturesInOrder(sourcePicturesDir,targetPicturesDir,targetNum):
    sourcePictureFiles = batchGetPictureFiles(sourcePicturesDir)  #源文件夹下图片的数量
    sourceFilesNum = len(sourcePictureFiles)


    for ind in range(targetNum):

        sourcePictureFile = sourcePictureFiles[ind%sourceFilesNum]
        targetPictureFile = os.path.join(targetPicturesDir,"frame{}.jpg".format(ind+1))

        with open(sourcePictureFile,"rb") as rf:
            with open(targetPictureFile,"wb") as wf:
                wf.write(rf.read())

        print(sourcePictureFile,targetPictureFile)

if __name__ == '__main__':
    sourcePicturesDir = "D:\\project\\AtlasMeshReiver\\data\\data"
    targetPicturesDir = "D:\\project\\demo-example-win\\data\\images"
    targetNum = 1000
    batchSavePicturesInOrder(sourcePicturesDir,targetPicturesDir,targetNum)